package com.hdax.dmw.pay.api;

import com.hdax.dmw.entity.pay.DmTrade;
import com.hdax.dmw.pay.feign.OrderFeign;
import com.hdax.dmw.pay.service.DmTradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class AliPaySuccessApi {

    @Autowired
    private DmTradeService tradeService;
    @Autowired
    private OrderFeign orderFeign;

    @PostMapping(path = "/pay/success")
    public void success(HttpServletRequest request){
        System.out.println("支付宝交易单号："+request.getParameter("trade_no"));
        System.out.println("商户订单号："+request.getParameter("out_trade_no"));
        System.out.println("卖家账号："+request.getParameter("seller_id"));
        System.out.println("买家账号："+request.getParameter("buyer_id"));
        System.out.println("订单费总金额："+request.getParameter("total_amount"));
        DmTrade entity = new DmTrade();
        entity.setOrderNo(request.getParameter("out_trade_no"));
        entity.setTradeNo(request.getParameter("trade_no"));
        entity.setAmount(Double.parseDouble(request.getParameter("total_amount")));
        entity.setPayMethod(1);
        tradeService.save(entity);
        orderFeign.update(request.getParameter("out_trade_no"),request.getParameter("trade_no"));
    }
}
